/*
 *  include/asm/asmdef.h
 *
 *  last modified 2007.07.14 21:51 by ChenJie
 *
 */

#ifndef ASMDEF_H
#define ASMDEF_H

#define ENTRY(name) \
	.global name; \
	.align 2; \
	name:

#define SAVE_REGS() \
	push	%gs;  \
	push	%fs;  \
	push	%es;  \
	push	%ds;  \
	pushl	%ebp; \
	pushl	%esi; \
	pushl	%edi; \
	pushl	%edx; \
	pushl	%ecx; \
	pushl	%ebx; \
	pushl	%eax; \
	movw	$KERNEL_DS, %ax; \
	movw	%ax, %ds; \
	movw	%ax, %es; \
	movw	$USER_DS, %ax; \
	movw	%ax, %fs; \
	movw	$0x18, %ax; \
	movw	%ax, %gs; \
	movl	%esp, %ebp;

#define RESTORE_REGS() \
	popl	%eax; \
	popl	%ebx; \
	popl	%ecx; \
	popl	%edx; \
	popl	%edi; \
	popl	%esi; \
	popl	%ebp; \
	pop	%ds; \
	pop	%es; \
	pop	%fs; \
	pop	%gs;

#define LEAVE() \
	iret;

//采用SAVE_REGS()时堆栈中的寄存器的偏移量(ebp作基址)：
#define OLDSS	0x3C
#define OLDESP	0x38

#define EFLAGS	0x34
#define CS	0x30
#define EIP	0x2C

#define GS	0x28
#define FS	0x24
#define ES	0x20
#define DS	0x1C
#define EBP	0x18
#define ESI	0x14
#define EDI	0x10
#define EDX	0x0C
#define ECX	0x08
#define EBX	0x04
#define EAX	0x00		# <----%ebp


#endif // ASMDEF_H
